package com.m4f.web.bind;

import java.util.List;
import org.springframework.beans.propertyeditors.CustomBooleanEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.propertyeditors.CustomCollectionEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

public class TheFocusBindingInitializer extends ConfigurableWebBindingInitializer  {
	
	public void initBinder(WebDataBinder binder, WebRequest request) {        
		/*Necessary to run into GAE.*/
		binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
		binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor("true", "false", true));
        binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class,true));
        binder.registerCustomEditor(List.class, new CustomCollectionEditor(List.class, true));
        binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, null, true));
        binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, null, true));
        binder.registerCustomEditor(Float.class, null, new CustomNumberEditor(Float.class, null, true));
        /*To validate and more actions. */
        super.initBinder(binder, request);
	}
	
}